﻿using Quartz;
using Microsoft.Extensions.DependencyInjection;

namespace broMap.System.Jobs
{
    /// <summary>  
    /// Quartz任务调度器配置  
    /// </summary>  
    public static class QuartzJobSchedulerExtensions
    {
        public static IServiceCollection AddQuartzJobScheduler(this IServiceCollection services)
        {
            services.AddQuartz(q =>
            {
                // 创建热榜数据获取作业  
                var jobKey = new JobKey("HotListFetchJob");

                q.AddJob<HotListFetchJob>(opts => opts.WithIdentity(jobKey));

                // 创建触发器 - 每天多次执行（可以根据需求调整）  
                //q.AddTrigger(opts => opts
                //    .ForJob(jobKey)
                //    .WithIdentity("HotListFetchTrigger-Morning")
                //    .WithCronSchedule("0 0 8 * * ?")); // 上午8点  

                q.AddTrigger(opts => opts
                    .ForJob(jobKey)
                    .WithIdentity("HotListFetchTrigger-Evening")
                    .WithCronSchedule("0 0 22 * * ?")); // 晚上10点  
            });

            // 添加Quartz服务  
            services.AddQuartzHostedService(q => q.WaitForJobsToComplete = true);

            return services;
        }
    }
}